package org.lixue.game.server.test;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MessageClientHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void handlerAdded(ChannelHandlerContext ctx) {
        log.debug("channelAdded");
    }

    @Override
    public void channelRegistered(ChannelHandlerContext ctx) {
        log.debug("channelRegistered");
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        log.debug("channelActive");
        //TODO 连接成功后处理
        ctx.writeAndFlush("hello server");
    }

    @Override
    public void handlerRemoved(ChannelHandlerContext ctx) {
        log.debug("channelRemoved");
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        log.debug("channelRead:" + msg);
        //TODO 消息分发
    }

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        super.userEventTriggered(ctx, evt);
        log.debug("userEventTriggered:{}", evt);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        log.error("exceptionCaught:{}", cause.getMessage());
        ctx.close();
    }
}
